<template>
	<view class="">
		<u-navbar title="经典案例" background="url('https://www.yplm888.com//uploads/20220803/7ed305f9a93ba50b049a7725662b18cc.png') no-repeat"></u-navbar>
		<view class="">
			<my-input @search="search" :value='searchVaule'></my-input>
		</view>
		<scroll-view class="" :scroll-y="true" :style="'height:' + scrollH+'rpx;'" @scrolltolower="lowerBottom" refresher-enabled="true"
			:refresher-triggered="triggered" :refresher-threshold="50" @refresherpulling="onPulling"
			@refresherrefresh="onRefresh" @refresherrestore="onRestore" @refresherabort="onAbort">
			<view v-if="dataList.length>0" class="page">
				<audios-list :dataList='dataList' :pageType='"case"'></audios-list>
			</view>
			<view v-else style="margin-top:150rpx">
				<no-thing></no-thing>
			</view>
		</scroll-view>
	</view>

</template>

<script>
	import audiosList from '../components/audios-list.vue';
	import myInput from '../components/my-input.vue';
	export default {
		components: { audiosList,myInput },
		data() {
			return {
				dataList: [],
				page: 1,
				scrollH: 0,
				searchVaule:'',
				triggered: false,
			}
		},
		mounted() {
			this._freshing = false;
			this.initData()
		},
		onReady() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					that.scrollH = res.windowHeight * 750 / res.windowWidth;
					// #ifdef MP-WEIXIN
					that.scrollH = res.windowHeight * 750 / res.windowWidth - parseInt(res.safeArea.top) - 200;
					// #endif
				}
			});
		},
		onReachBottom() {
			this.page++
			this.initData()
		},
		methods: {
			initData() {
				let data = {
					page: this.page,
					limit: 10,
					keyword: this.searchVaule
				}
				this.$u.api.getCase(data).then(res => {
					if (res.code == 1) {
						this.dataList = [...this.dataList,...res.data]
					} else {
						this.$u.toast(res.msg)
					}

				})
			},
			// 搜索的值
			search(value) {
				console.log(value)
				this.searchVaule = value
				this.dataList = []
				this.initData() 
			},
			onPulling(e) {
				this.triggered = true;
			},
			async onRefresh() {
				if (this._freshing) return;
				this._freshing = true;
				this.page = 1;
				await setTimeout(() => {
					this.triggered = false;
					this._freshing = false;
					this.dataList = []
					this.initData();
				}, 1000);
				uni.showToast({
					title: '刷新成功',
					duration: 1000
				})
			},
			onRestore() {
				this.triggered = false; // 需要重置
				console.log("onRestore");
			},
			onAbort() {
				console.log("onAbort");
			},
			// 触底加载
			lowerBottom() {
				this.page++;
				this.initData();
			}
		}
	}
</script>

<style lang="scss">
	.page {
		padding: 20rpx 40rpx;
	}
</style>
